package logic

import (
	"context"
	"src/models/mysql"
	"src/srcclient"

	"src/internal/svc"
	"src/src"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *src.OrderListRequest) (*src.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	var Order []mysql.Order
	mysql.DB.Debug().Model(&Order).Where("status   like ?", "%"+in.Status+"%").Find(&Order)

	var slice []*srcclient.OrderListStruct

	for _, V := range Order {
		list := srcclient.OrderListStruct{
			UserId:    int64(V.UserId),
			Total:     int64(V.Total),
			NumberInt: V.NumberInt,
			Status:    int64(V.Status),
			Title:     V.Title,
		}
		slice = append(slice, &list)
	}
	return &src.OrderListResponse{OrderList: slice}, nil
}
